package com.lcx.myservice;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private static final String TAG = "lcx_debug";
    TextView tv;
    Button btn_start;
    Button btn_stop;
    Intent intent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        init();
    }
    private void init(){
        btn_start = findViewById(R.id.tv_start);
        btn_stop = findViewById(R.id.tv_stop);
        btn_start.setOnClickListener((View.OnClickListener) this);
        btn_stop.setOnClickListener((View.OnClickListener) this);
        tv = findViewById(R.id.textView);
        tv.setText("Hello World");
    }

    /**
     * Called when a view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        intent = new Intent(this, MyIntentService.class);
        switch (v.getId()){
            case R.id.tv_start:
                Log.d(TAG, "onClick:start ");
                intent.putExtra("num","1");
                break;
            case R.id.tv_stop:
                Log.d(TAG, "onClick:stop ");
                intent.putExtra("num","2");
                break;
        }
        MainActivity.this.startService(intent);
    }
}